package cn.edu.lingnan.service.imp;


import cn.edu.lingnan.dao.CourseMapper;
import cn.edu.lingnan.dao.ScoreMapper;
import cn.edu.lingnan.pojo.Course;
import cn.edu.lingnan.pojo.Student;
import cn.edu.lingnan.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Scanner;

@Service
public class CourseServiceImp implements CourseService {
    @Autowired
    CourseMapper courseMapper;

    @Autowired
  ScoreMapper scoreMapper;
    @Override
    public Integer insert() {
        Course course=new Course();
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入课程号");
        course.setCid(sc.next());
        System.out.println("请输入课程名");
        course.setCname(sc.next());
        System.out.println("请输入课程标志");
        course.setCflag(sc.nextInt());
        return courseMapper.insert(course);
    }

    @Override
    public Integer deleteById(String cid) {
//        scoreMapper.deleteById(cid);
        return courseMapper.deleteById(cid);
    }

    @Override
    public Integer updateById() {
        Course course=new Course();
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入需要修改的课程号");
        course.setCid(sc.next());
        System.out.println("请输入修改后的课程名");
        course.setCname(sc.next());
        System.out.println("请输入修改后的课程标志");
        course.setCflag(sc.nextInt());
        return courseMapper.updateById(course);
    }

    @Override
    public Course getById() {
        System.out.println("请输入你需要查询的课程id");
        Scanner sc=new Scanner(System.in);
        String cid=sc.next();
        return courseMapper.getById(cid);
    }

    public  void CourseAction(){
        System.out.println("                --欢迎进入课程信息管理系统--");
        System.out.println("----------------------------------------------------------------");
        while (true){
            System.out.println(" 1:添加课程信息  2:删除课程信息 3:修改课程信息 4:查询课程信息 0:退出");
            Scanner sc=new Scanner(System.in);
            Integer  selectflag=sc.nextInt();
            if (selectflag ==0){
                System.out.println("已退出课程信息管理系统");
                break;
            }
            switch (selectflag){
                case 1:Integer n1= insert();
                    System.out.println("成功插入"+n1+"条数据");
                    break;

                case 2:
                    System.out.println("请输入你需要删除课程的id");
                    Integer n2=deleteById(sc.next());
                    System.out.println("成功删除"+n2+"条数据");
                    break;

                case 3:
                    Integer n= updateById();
                    System.out.println("成功修改"+n+"条数据");
                    break;

                case 4:
                    Course course=getById();
                    System.out.println(course);
                    break;
                default:
                    System.out.println("您的输入有误");
                    break;
            }

        }
    }
}
